<?php
namespace app\madmin\controller;
use app\madmin\model\SystemRuleModel;

/**
 * 菜单控制器
 * @author  黄明杰 vx:HMJ125855
 * @version 20190101
 */
class SystemRule extends PublicBase{

	# 菜单列表方法
    public function showList(){
        $SystemRule = new SystemRuleModel;

        $Where = $this->getFormWhere();

        $Admin = $this->checkLogin();

        if($Admin['AdminID'] != 1){
            $Where['rule_hide'] = 1;
        }

        $Lists = $SystemRule->mList($Where, '*');

        return $this->fetch('SystemRule/showList', [
            'Lists' => $SystemRule::mTree($Lists)
        ]);
    }

    # 菜单新增方法
    public function showAdd(){
    	$SystemRule = new SystemRuleModel;

        if(request()->isPost()){
            $Param = input('post.');

            $Back = $SystemRule->mAdd($Param);

            $this->ShowData($Back['code'], $Back['msgs'], $Back['urls']);
        }else{
            return $this->fetch('SystemRule/showAdd', [
                'Info'  => Null,
                'Rule'  => $this->showRule(),
                'Icon'  => $this->getLexiconCache('FONT_ICON'),
                'User'  => $this->checkLogin()
            ]);
        }
    }

    # 菜单更新方法
    public function showEdit(){
    	$SystemRule = new SystemRuleModel;

        $ID = input('param.id');

        if(request()->isPost()){
            $Param = input('post.');

            $Back = $SystemRule->mEdit(['rule_id'=>$ID], $Param);

            $this->ShowData($Back['code'], $Back['msgs'], $Back['urls']);
        }else{
            $Info = $SystemRule->mInfo(['rule_id'=>$ID]);

            if(empty($Info)){
                $this->ShowData(2, lang('XtCwCxCw'));
            }

            return $this->fetch('SystemRule/showAdd', [
                'Info'  => $Info,
                'Rule'  => $this->showRule(),
                'Icon'  => $this->getLexiconCache('FONT_ICON'),
                'User'  => $this->checkLogin()
            ]);
        }
    }

    # 菜单删除方法
    public function showDel(){
    	if(request()->isPost()){
            $SystemRule = new SystemRuleModel;

            $ID = input('post.id');

            $Back = $SystemRule->mDel(['rule_id'=>$ID]);

            $this->ShowData($Back['code'], $Back['msgs']);
        }
    }

    # 菜单下拉方法
    private function showRule(){
        $SystemRule = new SystemRuleModel;

        $Where = [];
        $Where['rule_state'] = 1;
        $Where['rule_show'] = 1;

        $Lists = $SystemRule->mAll($Where);

        return $SystemRule::mTree($Lists);
    }

}